//如果有未处理的异常抛出，可以在这里捕获到
process.on('uncaughtException', function (err) {
    console.log(err.stack);
});

var n2MvcServer = require('./server');
n2MvcServer.runServer();

var tcpClient = require('./tcpClient');
var wsServer = require('./wsServer')

var myServer = new wsServer.Server(5354);
myServer.on('connect', function (_client) {
    var wsClient = _client;
    wsClient.on('data', function (data) {
        try {
            var json = JSON.parse(data);
            liveClient.send(json.tid, json.content);
        } catch (ex) {
            console.log({ 'unknownJson': data });
        }
    });
    wsClient.on('close', function () {
        wsClient = null;
        liveClient.close();
    });

    var liveClient = new tcpClient.Client('192.168.1.13', 9201);
    liveClient.on('connect', function () {
    });
    liveClient.on('data', function (tid, content) {
        if (wsClient) {
            var obj = { 'tid': tid || 0, 'content': content };
            var msg = JSON.stringify(obj);
            wsClient.send(msg);
        }
    });
});

var rl = require('readline');
rl.createInterface(process.stdin, process.stdout, null)
    .on('line', function (data) {

    });